package com.example.module_maintenance

import androidx.appcompat.app.AppCompatActivity
import android.os.Bundle
import androidx.lifecycle.ViewModelProvider
import androidx.recyclerview.widget.LinearLayoutManager
import com.alibaba.android.arouter.facade.annotation.Route
import com.alibaba.android.arouter.launcher.ARouter
import com.bw.lib_base.path.RouterPath
import com.bw.lib_base.view.BaseActivity
import com.bw.lib_common.vm.BaseViewModel
import com.bw.lib_common.vm.BaseViewModel2
import com.example.module_maintenance.adapter.RepairAdapter
import com.example.module_maintenance.databinding.ActivityRepairBinding
import com.example.module_maintenance.viewmodel.RepairViewModel
import dagger.hilt.android.AndroidEntryPoint

@AndroidEntryPoint
@Route(path = RouterPath.PATH_REPAIR_ACTIVITY)
class RepairActivity : BaseActivity<ActivityRepairBinding>() {

    private val vm by lazy { ViewModelProvider(this)[RepairViewModel::class.java] }

    private val repairAdapter by lazy { RepairAdapter() }

    override fun initView() {
        mDataBinding.whRv.adapter = repairAdapter
        mDataBinding.whRv.layoutManager = LinearLayoutManager(this)
        vm.getRepair()

        vm.getRepairSuccess.observe(this){
            repairAdapter.data.clear()
            repairAdapter.data.addAll(it)
            repairAdapter.notifyDataSetChanged()
        }
        mDataBinding.add.setOnClickListener {
            ARouter.getInstance().build(RouterPath.PATH_ADD_REPAIR_ACTIVITY).navigation()
        }
    }



    override fun getLayoutId(): Int = R.layout.activity_repair


}